package com.mall.search.controller;

import com.mall.search.model.SkuEs;
import com.mall.search.service.ISkuSearchService;
import com.mall.common.util.RespResult;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author Darren
 * @date 2022-08-22 15:23
 * Description：
 */
@RestController
@RequestMapping("/search/sku")
public class SkuSearchController {
    @Autowired
    private ISkuSearchService skuSearchService;

    @RequestMapping("/addIndex")
    @ApiOperation(value = "增加索引")
    public RespResult addIndex(@RequestBody SkuEs skuEs) {
        skuSearchService.addIndex(skuEs);
        return RespResult.ok();
    }

    @RequestMapping("/delIndex/{id}")
    @ApiOperation(value = "删除索引")
    public RespResult delIndex(@PathVariable("id") String id) {
        skuSearchService.delIndex(id);
        return RespResult.ok();
    }

    @GetMapping
    @ApiOperation(value = "根据关键词搜索")
    @ApiImplicitParam(name = "keywords", value = "关键词")
    public RespResult<Map<String, Object>> search(@RequestParam(required = false) Map<String, Object> searchMap) {
        return RespResult.ok(skuSearchService.search(searchMap));
    }

    @PostMapping("refreshIndex")
    @ApiOperation(value = "刷新全部索引")
    public RespResult refreshIndex() {
        skuSearchService.refreshIndex();
        return RespResult.ok();
    }
}
